package com.example.jacky.android_easeui.base;

import android.os.Bundle;

import com.example.jacky.android_easeui.R;
import com.example.jacky.uilibrary.view.SwipeToActivityFinishLayout;

/**
 * 滑动关闭页面基类，使用时继承此类并使用BlankTheme主题即可
 */
public class SwipeActivity extends BaseActivity {

    private SwipeToActivityFinishLayout mSwipeLayout;
    private boolean swipeFinished = false;

    public SwipeActivity() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mSwipeLayout = new SwipeToActivityFinishLayout(this);
        mSwipeLayout.setOnSwipeListener(new SwipeToActivityFinishLayout.OnSwipeListener() {
            @Override
            public void onFinishingActivity() {
                swipeFinished = true;
            }
        });
    }

    public void setSwipeAnyWhere(boolean mSwipeAnyWhere) {
        mSwipeLayout.setSwipeAnyWhere(mSwipeAnyWhere);
    }

    public void setSwipeEnabled(boolean mSwipeEnabled) {
        mSwipeLayout.setSwipeEnabled(mSwipeEnabled);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mSwipeLayout.replaceLayer(this);
    }


    @Override
    public void finish() {
        if (swipeFinished) {
            super.finish();
            overridePendingTransition(0, 0);
        } else {
            mSwipeLayout.cancelPotentialAnimation();
            super.finish();
            overridePendingTransition(0, R.anim.slide_out_right);
        }
    }
}
